package net.begincode.biz.impl;

import com.google.common.base.Preconditions;
import net.begincode.biz.KeyWordsBiz;
import net.begincode.blog.bean.param.KeyWordsQueryParam;
import net.begincode.blog.bean.vo.HotKeyWord;
import net.begincode.blog.entity.KeyWords;
import net.begincode.blog.service.KeyWordsService;
import net.begincode.json.JsonUtil;
import net.begincode.page.PageResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class KeyWordsBizImpl implements KeyWordsBiz {
    private final Logger LOGGER = LoggerFactory.getLogger(KeyWordsBizImpl.class);
    @Resource
    private KeyWordsService keyWordsService;

    @Override
    public PageResponse<KeyWords> queryKeyWords(KeyWordsQueryParam keyWordsQueryParam) {
        return keyWordsService.queryKeyWords(keyWordsQueryParam);
    }

    @Override
    public int addKeyWords(KeyWords keyWords) {
        return keyWordsService.addKeyWord(keyWords);
    }

    @Override
    public int delKeyWords(long keyWordsId) {
        Preconditions.checkArgument(keyWordsId != 0, "keyWordsId not zero");
        return keyWordsService.delKeyWordById(keyWordsId);
    }

    @Override
    public int updateKeyWordsById(KeyWords keyWords) {
        if(LOGGER.isDebugEnabled()){
            LOGGER.info(JsonUtil.toJson(keyWords));
        }
        return keyWordsService.updateKeyWordById(keyWords);
    }

    @Override
    public KeyWords queryById(Long keyWordId) {
        return keyWordsService.selectById(keyWordId);
    }

    @Override
    public List<HotKeyWord> queryHotKeyWord(Integer limit) {
       return keyWordsService.queryHotKeyWord(limit);
    }
}
